
#ifndef  FS_H
#define  FS_H

#include "types.h"

#define ROOTINO   1
#define BSIZE     1024


#define FSMAGIC 0x10203040

struct superblock {
  uint magic;
  uint size;      //size of file system images(blocks)
  uint nblocks;   //number of data blocks
  uint ninodes;   //number of inodes
  uint nlog;      //number of log blocks
  uint logstart;  //blockno of first log block  (log header)
  uint inodestart;//blockno of first inode block
  uint bmapstart; //blockno of first free map block
};


#define NDIRECT   12
#define NINDRECT  (BSIZE/sizeof(uint))
#define MAXFILE  (NDIRECT + NINDRECT)

struct dinode {
  short type;
  short major;
  short minor;
  short nlink;
  uint size;
  uint addrs[NDIRECT + 1];
};

// inodes per block
#define IPB       ((BSIZE)/sizeof(struct dinode))
//block containing inode i in device
#define IBLOCK(i, sb)     (((i)/IPB) + (sb).inodestart)

// bitmap bits per block |  blocknos per block
#define BPB       ((BSIZE)*8) 
//bitmap block id for data byte offset
#define BBLOCK(b, sb)    (((b)/BPB) + (sb).bmapstart)



#define DIRSIZE 14


struct dirent {
  ushort inum;
  char name[DIRSIZE];
};



#endif   /* FS_H */
